package com.weirdor.mongo.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常相关工具类
 * @Author werdor
 * @Date 2021/11/9 11:44 上午
 **/
public class ExceptionUtils {
    /**
     * 获取异常栈信息
     *
     * @param e
     * @return
     */
    public static String getExceptionStack(Exception e) {
        try (StringWriter sw = new StringWriter()) {
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            return sw.toString();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return null;
    }
}
